package myjava.util;

import org.junit.Test;

import java.util.List;

/**
 * <p>
 * 我的二叉树
 * </p>
 *
 * @author Eric
 * @version 1.0
 * @date 2019-07-03
 */
public class MyBinTree {

    private BinTree binTree;

    private BinTree recursionTree;

    @Test
    public void test(){
        BinTree tree=null;
        add(tree,7);
        add(tree,3);
        add(tree,4);
        add(tree,10);
        add(tree,11);
        add(tree,5);

        System.out.println(tree);
    }
    public boolean add(BinTree binTree,Integer num) {
        if (binTree == null) {
            binTree = new BinTree();
            binTree.setVal(num);
        } else {
            if (binTree.getVal() > num) {
                if (binTree.getLeft() != null) {
                    add(binTree.getLeft(), num);
                } else {
                    binTree.setLeft(new BinTree(num));
                }
            } else {
                if (binTree.getLeft() != null) {
                    add(binTree.getLeft(), num);
                } else {
                    binTree.setLeft(new BinTree(num));
                }
            }
        }
        this.binTree = binTree;
        return true;
    }

    public boolean remove() {
        return false;
    }

    /**
     * <p>
     * 转成有序 列表
     * </p>
     *
     * @return java.util.List<java.lang.Integer>
     * @throws
     * @author Eric
     * @date 2019/7/3
     **/
    public List<Integer> toList() {
        return null;
    }
}

class BinTree {

    private Integer val;

    private BinTree left;

    private BinTree right;

    public BinTree() {
        this(null);
    }

    public BinTree(Integer val) {
        this(val, null, null);
    }

    public BinTree(Integer val, BinTree left, BinTree right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }

    public int getVal() {
        return val;
    }

    public void setVal(int val) {
        this.val = val;
    }

    public BinTree getLeft() {
        return left;
    }

    public void setLeft(BinTree left) {
        this.left = left;
    }

    public BinTree getRight() {
        return right;
    }

    public void setRight(BinTree right) {
        this.right = right;
    }

}
